/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoBloom.go			*/
/********************************************************/

package GoCls

import (
	//. "GoGlb"
)

const (
	GO_BL_0001	byte = 0x80
	GO_BL_0002	byte = 0x40
	GO_BL_0003	byte = 0x20
	GO_BL_0004	byte = 0x10
	GO_BL_0005	byte = 0x08
	GO_BL_0006	byte = 0x04
	GO_BL_0007	byte = 0x02
	GO_BL_0008	byte = 0x01
)

const (
	GO_BL_01GB	uint64 = 1048576 * 1024
	GO_BL_02GB	uint64 = GO_BL_01GB * 2
	GO_BL_04GB	uint64 = GO_BL_01GB * 4
	GO_BL_08GB	uint64 = GO_BL_01GB * 8
)

var mask = []byte{GO_BL_0001, GO_BL_0002, GO_BL_0003, GO_BL_0004, GO_BL_0005, GO_BL_0006, GO_BL_0007, GO_BL_0008}

type GoBloom struct {
	bloom	[]byte
	length	uint64
}

func (b *GoBloom) GoBloomGet() []byte {
	return b.bloom
}

func (b *GoBloom) GoBloomSize() uint64 {
	return b.length
}

func (b *GoBloom) GoBloomMake(length uint64) {
	b.bloom = make([]byte, length)
	b.length = length
}

func (b *GoBloom) GoBloomUpdate(value uint64) {
	b.bloom[value % b.length] |= mask[value % 8]
}

func (b *GoBloom) GoBloomCheck(value uint64) bool {
	return 0 != mask[value % 8] & b.bloom[value % b.length]
}
